//import and format psid data
clear all
do "$data/PSID/weights_2/J331663"
do "$data/PSID/weights_2/J331663_formats"

gen uniqid = ER30001*1000 + ER30002 //generation of uniqid identifier variable
duplicates report uniqid //no duplicates!
drop ER30002 ER30000 

ds uniqid, not
foreach var in `r(varlist)'{
	
	//fetch label
	local lab: variable label `var'
	
	//kill sequence/release/interview numbers
	if strpos("`lab'", "SEQUENCE") | strpos("`lab'", "RELEASE") | strpos("`lab'", "INTERVIEW") |  strpos("`lab'", "RELATION"){
		drop `var'
		continue
	}
}
ds uniqid, not
foreach var in `r(varlist)'{
	di "`var'"
}



ren ER30019 weight_1968
ren ER30042 weight_1969
ren ER30066 weight_1970
ren ER30090 weight_1971
ren ER30116 weight_1972
ren ER30137 weight_1973
ren ER30159 weight_1974
ren ER30187 weight_1975
ren ER30216 weight_1976
ren ER30245 weight_1977
ren ER30282 weight_1978
ren ER30312 weight_1979
ren ER30342 weight_1980
ren ER30372 weight_1981
ren ER30398 weight_1982
ren ER30428 weight_1983
ren ER30462 weight_1984
ren ER30497 weight_1985
ren ER30534 weight_1986
ren ER30569 weight_1987
ren ER30605 weight_1988
ren ER30641 weight_1989
ren ER30686 weight_1990
ren ER30730 weight_1991
ren ER30803 weight_1992
ren ER30864 weight_1993
ren ER33119 weight_1994
ren ER33275 weight_1995
ren ER33318 weight_1996
ren ER33430 weight_1997
ren ER33546 weight_1999
ren ER33637 weight_2001
ren ER33740 weight_2003
ren ER33848 weight_2005
ren ER33950 weight_2007
ren ER34045 weight_2009
ren ER34154 weight_2011
ren ER34268 weight_2013
ren ER34413 weight_2015
ren ER34650 weight_2017
ren ER34863 weight_2019
ren ER35064 weight_2021

local even `"1998 2000 2002 2004 2006 2008 2010 2012 2014 2016"'
foreach num in `even'{
	local plus = `num' + 1
	gen weight_`num' = weight_`plus'
}

reshape long weight_, i(uniqid) j(year)
ren weight weight
save "$temp/psid_weights_2", replace



//end of dofile